//
//  ZGLShowPicCollectionVC.m
//  Faker
//
//  Created by dllo on 15/11/9.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import "ZGLShowPicCollectionVC.h"
#import "ZGLShowPicCell.h"

@interface ZGLShowPicCollectionVC () <UICollectionViewDataSource, UICollectionViewDelegate>

@property (nonatomic, strong) UICollectionView *outCollectionView;

@end

@implementation ZGLShowPicCollectionVC

- (void)setNavigationBar {
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"zaihufanhui"] style:(UIBarButtonItemStyleDone) target:self action:@selector(leftBarButtonItem:)];
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
}

- (void)leftBarButtonItem:(UIBarButtonItem *)button {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewWillAppear:(BOOL)animated {
    self.view.backgroundColor = backColor;
    _outCollectionView.backgroundColor = foreColor;
    self.tabBarController.tabBar.hidden = YES;
}

- (void)createCollectionView {
    UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc] init];
    flow.itemSize = CGSizeMake(ScaleX * 375, ScaleY * 603);
    flow.scrollDirection = 1;
    flow.minimumInteritemSpacing = 0;
    flow.minimumLineSpacing = 0;
    _outCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 64, ScaleX * 375, ScaleY * 603) collectionViewLayout:flow];
    _outCollectionView.dataSource = self;
    _outCollectionView.delegate = self;
    _outCollectionView.pagingEnabled = YES;
    [_outCollectionView registerClass:[ZGLShowPicCell class] forCellWithReuseIdentifier:@"ZGLShowPicCollectionVC_ZGLShowPicCell"];
    [self.view addSubview:_outCollectionView];
}

- (void)setModelArr:(NSMutableArray *)modelArr {
    if (_modelArr != modelArr) {
        _modelArr = modelArr;
    }
    [_outCollectionView reloadData];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNavigationBar];
    [self createCollectionView];
    // Do any additional setup after loading the view.
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    if (_modelArr.count == 0) {
        return 1;
    } else {
        return _modelArr.count;
    }
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    ZGLShowPicCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ZGLShowPicCollectionVC_ZGLShowPicCell" forIndexPath:indexPath];
    cell.backgroundColor = foreColor;
    if (_modelArr.count > 0) {
        cell.photoModel = _modelArr[indexPath.item];
        cell.allPage.text = [NSString stringWithFormat:@"/ %ld", _modelArr.count];
        cell.currentPage.text = [NSString stringWithFormat:@"%ld", indexPath.item + 1];
    }
    return cell;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
